package com.sgb.kjwl.view.ui.adapter.carrierDemand;

import android.content.Context;
import android.text.TextUtils;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.model.entity.DemandHallListEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;
import com.swgk.core.util.DateUtils;

import java.util.Arrays;
import java.util.List;

/**
 * @author Administrator
 */
public class DemandHallAdapter extends BaseRecycleAdapter<DemandHallListEntity> {
    public DemandHallAdapter(Context context, List<DemandHallListEntity> datas) {
        super(context, R.layout.item_demand_hall, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, DemandHallListEntity priceCheckEntity) {
        holder.setBinding(BR.viewModel, priceCheckEntity);
        ImageView pricestatus = holder.itemView.findViewById(R.id.price_status);
        TextView textView1 = holder.itemView.findViewById(R.id.shop_price_info1);
        TextView textView2 = holder.itemView.findViewById(R.id.shop_price_info2);
        TextView tvHallName = holder.itemView.findViewById(R.id.demand_hall_name);
        String name = priceCheckEntity.getCompanyName();
        //1代表是个人发布得询价 2 企业 3 团队 4 组织
        if (1 == priceCheckEntity.getAuthMethod()) {
            if (!TextUtils.isEmpty(name)) {
                char oldChar = name.charAt(0);
                name = name.replace(oldChar, "*".charAt(0));
                tvHallName.setText(name);
            }
        } else {
            tvHallName.setText(name);
        }
        if (priceCheckEntity.getItems() != null && priceCheckEntity.getItems().size() > 0) {
            textView1.setVisibility(View.VISIBLE);
        } else {
            textView1.setVisibility(View.GONE);
        }

        if (priceCheckEntity.getItems() != null && priceCheckEntity.getItems().size() > 1) {
            textView2.setVisibility(View.VISIBLE);
        } else {
            textView2.setVisibility(View.GONE);
        }
        if ("4".equals(priceCheckEntity.getStatus())) {
            pricestatus.setImageResource(R.mipmap.enquiry_finish);
        } else {
            pricestatus.setImageResource(R.mipmap.enquiry_start);
        }

        String wordStore = priceCheckEntity.getDeadlineTime();
        String[] word = wordStore.split("\\s+");
        List<String> wordsList = Arrays.asList(word);
        TextView sendTime = holder.itemView.findViewById(R.id.send_time);
//        sendTime.setText(wordsList.get(0));
        sendTime.setText(priceCheckEntity.getDeadlineTime());
    }
}
